import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { DoBootstrap, ApplicationRef } from '@angular/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClient } from '@angular/common/http';
import { NzMessageService } from 'ng-zorro-antd';

import { AppRoutingModule } from 'src/app/app-routing.module';
import { ShareModule } from 'src/app/share.module';
import { PasswordModule } from 'src/app/module/manage/users/password/password.module';

import { AppComponent } from 'src/app/index/app.component';
import { InfoComponent } from 'src/app/index/info.component';
import { InteractiveService } from 'src/app/index/interactive.service';

import { Protal1Component } from 'src/app/index/part/protal1.component';
import { Protal2Component } from 'src/app/index/part/protal2.component';
import { Mis1Component } from 'src/app/index/part/mis1.component';
import { Gis1Component } from 'src/app/index/part/gis1.component';
import { Gis2Component } from 'src/app/index/part/gis2.component';

import { registerLocaleData } from '@angular/common';
import zh from '@angular/common/locales/zh';

import { HttpUtils } from './http';

registerLocaleData(zh);

declare var base: any;
declare var security: any;

@NgModule({
  declarations: [
    AppComponent,
    InfoComponent,
    Protal1Component,
    Protal2Component,
    Mis1Component,
    Gis1Component,
    Gis2Component
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    NoopAnimationsModule,
    ShareModule,
    PasswordModule
  ],
  entryComponents: [
    AppComponent,
    InfoComponent
  ],
  providers: [
    InteractiveService
  ],
  bootstrap: []
})

export class AppModule implements DoBootstrap {

  constructor(
    private msg: NzMessageService,
    private http: HttpClient,
    private appRef: ApplicationRef) {
    const httpUtils = new HttpUtils(msg, http);
    httpUtils.initRemoteFun();
    this.initRemotePara();
  }

  ngDoBootstrap(appRef: ApplicationRef): void {
    // 启动系统登录时需关闭此功能
    // this.runComponent();
  }

  // 初始化后台参数
  private initRemotePara() {
    // 注册后台服务地址
     base.BaseService.setHostUrl('http://localhost:81');
   // base.BaseService.setHostUrl('http://129.28.30.232:81/xjmh');

    base.Factory.init(['security', 'form', 'bpm'], () => {
      // 系统登录
      security.SecurityService.confirmLogin(() => {
        this.runComponent();
      });
    });
  }

  // 运行组件
  private runComponent() {
    const info: string = window.location.href;
    if (info.indexOf('info=true') > 0) {
      this.appRef.bootstrap(InfoComponent);
    } else {
      this.appRef.bootstrap(AppComponent);
    }
  }
}
